package com.bestsoft.web.controller.flow;

import com.bestsoft.common.annotation.Log;
import com.bestsoft.common.core.controller.BaseController;
import com.bestsoft.common.core.domain.AjaxResult;
import com.bestsoft.common.core.page.TableDataInfo;
import com.bestsoft.common.enums.BusinessType;
import com.bestsoft.common.utils.poi.ExcelUtil;
import com.bestsoft.flow.domain.FlowUserGoods;
import com.bestsoft.flow.service.IFlowUserGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户商品关系Controller
 * 
 * @author 崔健
 * @date 2023-07-11
 */
@RestController
@RequestMapping("/flow/usergoods")
public class FlowUserGoodsController extends BaseController
{
    @Autowired
    private IFlowUserGoodsService flowUserGoodsService;

    /**
     * 查询用户商品关系列表
     */
    @PreAuthorize("@ss.hasPermi('flow:usergoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowUserGoods flowUserGoods)
    {
        startPage();
        List<FlowUserGoods> list = flowUserGoodsService.selectFlowUserGoodsList(flowUserGoods);
        return getDataTable(list);
    }

    /**
     * 导出用户商品关系列表
     */
    @PreAuthorize("@ss.hasPermi('flow:usergoods:export')")
    @Log(title = "用户商品关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowUserGoods flowUserGoods)
    {
        List<FlowUserGoods> list = flowUserGoodsService.selectFlowUserGoodsList(flowUserGoods);
        ExcelUtil<FlowUserGoods> util = new ExcelUtil<FlowUserGoods>(FlowUserGoods.class);
        util.exportExcel(response, list, "用户商品关系数据");
    }

    /**
     * 获取用户商品关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:usergoods:query')")
    @GetMapping(value = "/{usergoodsid}")
    public AjaxResult getInfo(@PathVariable("usergoodsid") Long usergoodsid)
    {
        return success(flowUserGoodsService.selectFlowUserGoodsByUsergoodsid(usergoodsid));
    }

    /**
     * 新增用户商品关系
     */
    @PreAuthorize("@ss.hasPermi('flow:usergoods:add')")
    @Log(title = "用户商品关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowUserGoods flowUserGoods)
    {
        return toAjax(flowUserGoodsService.insertFlowUserGoods(flowUserGoods));
    }

    /**
     * 修改用户商品关系
     */
    @PreAuthorize("@ss.hasPermi('flow:usergoods:edit')")
    @Log(title = "用户商品关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowUserGoods flowUserGoods)
    {
        return toAjax(flowUserGoodsService.updateFlowUserGoods(flowUserGoods));
    }

    /**
     * 删除用户商品关系
     */
    @PreAuthorize("@ss.hasPermi('flow:usergoods:remove')")
    @Log(title = "用户商品关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usergoodsids}")
    public AjaxResult remove(@PathVariable Long[] usergoodsids)
    {
        return toAjax(flowUserGoodsService.deleteFlowUserGoodsByUsergoodsids(usergoodsids));
    }
}
